package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description NursingProjectController
 * @Author zhangsuye
 * @Date 2024-10-15
 */
@RestController
@Api(tags = "护理项目相关接口")
@RequestMapping("/nursing_project")
public class NursingProjectController extends BaseController {

    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 查询护理项目列表
     *
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping
    @ApiOperation("查询护理项目列表")
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
            @ApiParam(value = "护理项目名称")
            String name,
            @ApiParam(value = "状态（0：禁用，1：启用）")
            Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1")
            Integer pageNum,
            @ApiParam(value = "每页显示条数")
            @RequestParam(value = "pageSize", defaultValue = "10")
            Integer pageSize
    ) {
        logger.info("查询护理项目列表 姓名：{} 状态：{} 当前页码：{} 每页显示条数：{}", name, status, pageNum, pageSize);
        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.getByPage(name, status, pageNum, pageSize);
        return success(pageResponse);
    }


    /**
     * 新增护理项目
     *
     * @param nursingProjectDto
     * @return
     */
    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult add(
            @ApiParam(value = "护理项目数据传输对象", type = "NursingProjectDto")
            @RequestBody NursingProjectDto nursingProjectDto) {
        logger.info("新增护理项目 请求参数：{}", nursingProjectDto);
        nursingProjectService.add(nursingProjectDto);
        return success();
    }

    /**
     * 根据id查询护理项目
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目")
    public ResponseResult<NursingProjectVo> getById(
            @ApiParam(value = "护理项目id")
            @PathVariable Long id) {
        logger.info("根据id查询护理项目 id：{}", id);
        NursingProjectVo nursingProjectVo = nursingProjectService.getById(id);
        return success(nursingProjectVo);
    }

    /**
     * 更新护理项目
     *
     * @param nursingProjectDto
     * @return
     */
    @PutMapping
    @ApiOperation("更新护理项目")
    public ResponseResult update(
            @ApiParam(value = "护理项目数据传输对象")
            @RequestBody NursingProjectDto nursingProjectDto
    ) {
        logger.info("更新护理项目 请求参数：{}", nursingProjectDto);
        nursingProjectService.update(nursingProjectDto);
        return success();
    }

    /**
     * 删除护理项目
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除护理项目")
    public ResponseResult deleteById(
            @ApiParam(value = "护理项目id")
            @PathVariable Long id
    ) {
        logger.info("删除护理项目 id:{}",id);
        nursingProjectService.delete(id);
        return success();
    }

    /**
     * 启用禁用护理项目
     * @param id
     * @param status
     * @return
     */
    @PutMapping("{id}/status/{status}")
    @ApiOperation("启用/禁用护理项目")
    public ResponseResult startOrStopStatus(
            @ApiParam(value = "护理项目id")
            @PathVariable Long id,
            @ApiParam(value = "状态（0：禁用，1：启用）")
            @PathVariable Integer status
    ){
        logger.info("启用/禁用护理项目 id:{} status:{}",id,status);
        nursingProjectService.startOrStopStatus(id,status);
        return success();
    }

    /**
     * 查询所有护理项目
     * @return
     */
    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult getAll() {
        logger.info("查询所有护理项目");
        List<NursingProjectVo> nursingProjectVoList = nursingProjectService.getAll();
        return success(nursingProjectVoList);
    }
}
